//
//  MainViewController.m
//  MicroBlog
//
//  Created by cocoazxj@163.com on 15/3/28.
//  Copyright (c) 2015年 handcool. All rights reserved.
//

#import "MainViewController.h"
#import "CustomTableViewCell.h"
#import "MicroBlogModel.h"

@interface MainViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) NSArray *mArray;
@end

@implementation MainViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (NSArray *)mArray
{
    if (!_mArray)
    {
        NSString *s = [[NSBundle mainBundle] pathForResource:@"statuses" ofType:@".plist"];
        NSArray *a = [NSArray arrayWithContentsOfFile:s];
        NSMutableArray *m = [NSMutableArray array];
        for(NSDictionary *d in a)
        {
            [m addObject:[MicroBlogModel microBlog:d]];
        }
        self.mArray = m;
    }
    return _mArray;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark -
#pragma mark UITableView
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.mArray.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MicroBlogModel *m = self.mArray[indexPath.row];
    NSLog(@"======1====%f",m.cellH);
    return m.cellH;
//    return 100;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"identifier";
    CustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if(cell == nil)
    {
        cell = [[CustomTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    MicroBlogModel *m = [self.mArray objectAtIndex:indexPath.row];
    NSLog(@"-----------%@",m.name);
    cell.microModel = m;
    return cell;
}
@end
